﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using BaseDll;
using CommonTools;
using MotionIoLib;
namespace StationDemo
{
    public static class Extension
    {
        public static bool Get(this IO_IN value)
        {
            bool res = IOMgr.GetInstace().ReadIoInBit($"{value}");
            return res;
        }
        //public static bool Get(this InputMotion value)
        //{
        //    bool res = IOMgr.GetInstace().ReadIoInBit($"{value}");
        //    return res;
        //}
        public static bool Set(this IO_OUT value, bool result)
        {
            bool res = IOMgr.GetInstace().WriteIoBit($"{value}", result);
            return res;
        }
        public static bool Get(this IO_OUT value)
        {
            bool res = IOMgr.GetInstace().ReadIoOutBit($"{value}");
            return res;
        }
        public static string ToStringFFF(this DateTime value)
        {
            string res = $"{value.ToString("yyyyMMdd_HHmmssfff")}";
            return res;
        }
        public static string ToStringDay(this DateTime value)
        {
            string res = $"{value.ToString("yyyy-MM-dd")}";
            return res;
        }
        public static void ToSleep(this int value)
        {
            Thread.Sleep(value * 1000);
        }
        public static void Bee(int count = 1, double time = 0.5)
        {
            for (int i = 0; i < count; i++)
            {
                IOMgr.GetInstace().WriteIoBit($"{IO_OUT.蜂鸣}", true);
                Thread.Sleep((int)(time * 1000));
                IOMgr.GetInstace().WriteIoBit($"{IO_OUT.蜂鸣}", false);
                Thread.Sleep((int)(time * 1000 * 0.6));
            }
        }
        public static Coordinate ToCoord(this PointInfo point)
        {
            Coordinate coord = new Coordinate();
            coord.X = point.pointX;
            coord.Y = point.pointY;
            coord.Z = point.pointZ;
            coord.U = point.pointU;
            return coord;
        }
        public static PointInfo ToPointInfo(this Coordinate point)
        {
            PointInfo pointInfo = new PointInfo();
            pointInfo.pointX = point.X;
            pointInfo.pointY = point.Y;
            pointInfo.pointZ = point.Z;
            pointInfo.pointU = point.U;
            return pointInfo;
        }
        public static XYUPoint ToXYUPoint(this Coordinate point)
        {
            XYUPoint pointInfo = new XYUPoint();
            pointInfo.x = point.X;
            pointInfo.y = point.Y;
            pointInfo.u = point.U;
            return pointInfo;
        }
        public static XYUPoint ToXYUPoint(this PointInfo point)
        {
            XYUPoint pointInfo = new XYUPoint();
            pointInfo.x = point.pointX;
            pointInfo.y = point.pointY;
            pointInfo.u = point.pointU;
            return pointInfo;
        }
    }
}
